//
//  KKApplyExpertTimeVC.m
//  DoMi
//
//  Created by 康凯 on 2016/12/7.
//  Copyright © 2016年 kk. All rights reserved.
//

#import "KKApplyExpertTimeVC.h"
#import "KKComHttp.h"

@interface KKApplyExpertTimeVC ()
@property (weak, nonatomic) IBOutlet UITextField *inputTime;
@property (weak, nonatomic) IBOutlet UIDatePicker *datePicker;

@end

@implementation KKApplyExpertTimeVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title=@"申请成为专家";
    [self initNav];
    [self.datePicker setLocale:[NSLocale currentLocale]];
    [self.datePicker addTarget:self action:@selector(selectDate:) forControlEvents:UIControlEventValueChanged];
}

#pragma mark ---初始化nav
-(void)initNav{
    //禁止透明
    self.navigationController.navigationBar.translucent=NO;
    //电量颜色设置UIStatusBarStyleLightContent
    [UIApplication sharedApplication].statusBarStyle=UIStatusBarStyleDefault;
    //背景颜色
    self.navigationController.navigationBar.barTintColor=[UIColor colorWithHexString1:@"#F7F8F9"];
    //标题字体颜色
    self.navigationController.navigationBar.titleTextAttributes=[NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor],NSForegroundColorAttributeName, nil];
    //返回字体颜色
    self.navigationController.navigationBar.tintColor=[UIColor whiteColor];
    
    //左侧排行榜
    UIButton *leftBtn = [[UIButton alloc ]initWithFrame:CGRectMake(0, 0, 12, 20)];
    [leftBtn setImage:[UIImage imageNamed:@"back_blue"] forState:UIControlStateNormal];
    
    [leftBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];

}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}

- (IBAction)commitClick:(id)sender {
    if([KKAppUtils isEmptyString:self.inputTime.text]){
        [self toast:@"请选择预约时间"];
        return;
    }
    [self commitTime];
}

#pragma mark 点击--返回
-(void)back{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark 点击--选择日期
-(void)selectDate:(UIDatePicker *)date{
    NSDateFormatter *formatter=[[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd hh:mm"];
    self.inputTime.text=[formatter stringFromDate:date.date];
}

#pragma mark 接口--提交专家认证时间
-(void)commitTime{
    [self showDialog];
    [KKComHttp applyExpertTime:self.inputTime.text success:^(id data) {
        [self dismissDialog];
        [self toast:@"您的预约时间已提交"];
        [self.navigationController popViewControllerAnimated:YES];
    } failure:^(NSError *error) {
        [self dismissDialog];
    }];
}

@end
